<style>
    #box{
        padding: 15px;
    }
    h2{
        margin-top: 0;
    }

    .item .thumb{
        width: 80px;
        height: 80px;
        float: left;
        border: 1px solid #ddd;
    }

    .item .info{
        float: left;
        width : 60%;
        margin-left: 10px;
    }

    .item{
        border-bottom: 1px dashed #ddd;
        overflow: hidden;
        padding-bottom: 10px;
    }

    .item .action{
        clear: both;
        padding-top: 10px;
        text-align: center;
        font-size: 0.8em;
        line-height: 0.8em;
    }

    .price{
        display: block !important;
        font-size: 0.9em !important;
        margin-top: 8px !important;
    }

    .add_goods{
        text-align: center;
        display: block;
        margin-bottom: 20px;
        color: #fff !important;
        background: #D9434E;
        line-height: 35px;
        border-radius: 5px;
        margin-left: 10px;
        margin-right: 10px;
    }
</style>
<link rel="stylesheet" href="/distribute/template/static/css/pager.css"/>
<script src="/distribute/template/static/js/jquery.qrcode.js"></script>
<div id="box">

    <a href="/wap/tmpl/member/distribute_center.php?action=goods_list&type=cat" class="add_goods">添加商品</a>
    <p style="font-size: 0.8em;line-height: 1.2em;margin-bottom: 10px;text-align: center;">
        <span>
            提示：微信用户请先点击生成分享链接，再点击右上角的菜单进行分享
        </span>
    </p>
    <hr>

    <div style="height: 20px;"></div>
<?php
$m = Model("proxy_store_goods");
$list = $m->where(array('member_id' => $minfo['member_id']))->page(10)->select();
if ($list) {
    foreach ($list as $goods) {
        $ginfo = Model("goods_common")->find($goods["goods_commonid"]);
        $goods_info = Model()->table('goods')->where("goods_commonid = " . $goods['goods_commonid'])->find();
        $distribute = new Distribute($minfo['member_id']);
?>

    <div class="item" goods_id="<?php echo $goods_info['goods_id']?>">
        <img src="/data/upload/shop/store/goods/<?php echo $ginfo['store_id'] . '/' . $ginfo['goods_image']?>" alt="" class="thumb"/>
        <div class="info">
            <p class="name">
                <?php echo $ginfo['goods_name']; ?>
            </p>
            <p class="price" style="margin-top: 10px;">
                <span class="black">价格：</span>￥<?php echo $ginfo['goods_price']?>
            </p>
            <p class="price" style="margin-top: 10px;">
                <span class="black">预计佣金：</span>￥<?php echo $distribute->calMarginByGoods($goods_info['goods_id']);?>
            </p>
        </div>
        <div class="qrcode">

        </div>

        <div class="action">

<!--            <a href="javascript:;" class="make_qrcode" goods_commonid="--><?php //echo $ginfo['goods_commonid']?><!--" goods_id="--><?php //echo $goods_info['goods_id'];?><!--">-->
<!--                <i class="fa fa-hand-o-up"></i>-->
<!--                生成推荐二维码-->
<!--            </a>-->
            <a href="javascript:;" style="margin-left: 40px;" class="mk_share_link" goods_id="<?php echo $goods_info['goods_id'];?>" style="margin-left: 40px;">
                <i class="fa fa-hand-o-up"></i>
                生成分享链接
            </a>

            <a href="javascript:;" class="delete" style="margin-left: 40px;" goods_commonid="<?php echo $ginfo['goods_commonid']?>">
                <i class="fa fa-power-off"></i>
                删除
            </a>
        </div>
    </div>
<?php
    }

    ?>

    <div class="pagination">
        <?php
        echo $m->showpage();
        ?>
    </div>
    <?php
}else{
?>
<div style="padding-top: 15px;padding-bottom: 15px;text-align: center;">
    您还没有保存任何商品
</div>
<?php
}

?>

</div>

<div class="qrcode_box" style="display: none;">

</div>

<style>
    #mask{
        background: rgba(0,0,0,0.7);
        position: fixed;
        left: 0;
        top: 0;
        z-index: 10000;
        width : 100%;
        height: 100%;
        display: none;
    }
    #qrcodebox{
        position: fixed;
        left: 30%;
        top: 30%;
    }
    #qrcode{

    }

    .sr-bdimgshare{
        z-index: 10001;
    }

    .bds_more{
        display: none;
    }
    .bdimgshare-lbl{
        display: none;
    }
</style>
<div id="mask">
    <div style="background: #fff;border-radius: 10px;padding: 20px;" id="qrcodebox">
        <p style="font-size: 0.8em;text-align: center;margin-bottom: 10px;">
            点击图片可以分享
        </p>
        <img id="qrcode" width="150" height="150" src="" alt=""/>
    </div>
</div>



<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"image":{"viewList":["qzone","tsina","tqq","renren","weixin"],"viewText":"分享到：","viewSize":"16"}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>

<script>
    $('.item .thumb, .item .info .name').click(function(){
        var goods_id = $(this).closest(".item").attr('goods_id');
        location.href = '/wap/tmpl/product_detail.php?goods_id='+ goods_id;
    });

    $('.make_qrcode').click(function(){
        var goods_id = $(this).closest('.item').attr('goods_id');
        $('.qrcode_box').qrcode('<?php echo 'http://' . $_SERVER['HTTP_HOST'] . '/wap/tmpl/product_detail.php?goods_id=';?>' + $(this).attr('goods_id') + '&u=<?php echo base64_encode($minfo['member_id'])?>');
        console.log('<?php echo 'http://' . $_SERVER['HTTP_HOST'] . '/wap/tmpl/product_detail.php?goods_id=';?>' + $(this).attr('goods_id') + '&u=<?php echo base64_encode($minfo['member_id'])?>');

        var imgdata = $('.qrcode_box canvas')[0].toDataURL('image/png');

        $('#mask #qrcode').attr("src",imgdata);

        $("#qrcodebox").css("left",$(window).width() / 2 - 95);
        $("#qrcodebox").css("top",$(window).height() / 2 - 125);

        $("#mask").show();

//        layer.open({
//            type : 1,
//            content : "<img width='150' height='150' src='" + imgdata + "'",
//            time : 0,
//        });

    });

    $("#mask").click(function(e){
        if(e.target.id == "qrcode" || e.target.id == "qrcodebox"){
            return;
        }
        else{
            $("#mask").hide();
        }
    });

    $('.delete').click(function(){
        if(!confirm("删除后该商品不再计算佣金，确定要删除吗？")){
            return false;
        }
        var goods_commonid = $(this).attr('goods_commonid');
        var index = layer.load();
        $.post("/shop/index.php?act=seccode&op=delete_proxy_goods",{goods_commonid : goods_commonid},function(msg){
            layer.close(index);
            console.log(msg);
            if(msg == 'success') {
                layer.msg("删除成功", function () {
                    location.reload();

                });
            }
            else{
                layer.msg("删除失败",function() {
                    location.reload();
                });
            }
        });
    });
</script>

<?php
    require_wechat_js();
?>
<script>
    var share_data = {
        title: '', // 分享标题
        desc: '', // 分享描述
        link: '', // 分享链接
        imgUrl: '', // 分享图标
        type: '', // 分享类型,music、video或link，不填默认为link
        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
        success: function () {
            // 用户确认分享后执行的回调函数
        },
        cancel: function () {
            // 用户取消分享后执行的回调函数
        }
    }

    wx.ready(function() {
        wx.onMenuShareTimeline(share_data);
        wx.onMenuShareAppMessage(share_data);
        wx.onMenuShareQQ(share_data);
        wx.onMenuShareWeibo(share_data);
        wx.onMenuShareQZone(share_data);
    });
    $('.mk_share_link').click(function() {
        var _this = $(this);
        var pic = '<?php echo 'http://' . $_SERVER['HTTP_HOST'] ?>/' +_this.closest('.item').find('.thumb').attr('src');
        var title = _this.closest('.item').find('p.name').text().trim();
        var link = '<?php echo 'http://' . $_SERVER['HTTP_HOST'] . '/wap/tmpl/product_detail.php?goods_id=';?>' + $(this).attr('goods_id') + '&uid=<?php echo ($minfo['member_id'])?>';

        share_data.title = title;
        share_data.imgUrl = pic;
        share_data.link = link;

        wx.onMenuShareTimeline(share_data);
        wx.onMenuShareAppMessage(share_data);
        wx.onMenuShareQQ(share_data);
        wx.onMenuShareWeibo(share_data);
        wx.onMenuShareQZone(share_data);

        layer.msg("生成成功");


    })
</script>
